Make RAG preparation and retrieval non-blocking#557
Conversation
…ing rag retrieval
There was a problem hiding this comment.
Code Review
This pull request introduces asynchronous wrappers (aprepare_retriever and acall) for blocking RAG operations, utilizing asyncio.to_thread to prevent stalling the event loop. It also updates simple_chat.py and websocket_wiki.py to leverage these async methods and offload blocking calls like RAG initialization and file retrieval to worker threads. The review feedback highlights a critical issue with instantiating asyncio.Semaphore at the module level, which can lead to runtime errors due to binding to an inactive or incorrect event loop, and suggests lazily initializing the semaphore within the async method instead.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Summary
The async chat endpoints (
/chat/completions/streamand/ws/chat) callRAG.prepare_retriever()andRAG.callsynchronously, performing multiple blocking work -git clone, file io operations, embedding API calls, and query embedding - directly on the event loop thread, freezing the service and stalling all concurrent requests).This PR offloads the blocking work to worker threads so that the event loop stays responsive.